<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="用户" prop="userInformation.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择用户"
            labelName = 'userName'
            labelValue = 'id'
            :value = "inputForm.userInformation.id"
            :limit="1"
            @getValue='(value) => {inputForm.userInformation.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            dataListUrl="/dlyrl/hr/userinformation/userInformation/list"
            entityBeanName="userInformation"
            queryEntityUrl="/dlyrl/hr/userinformation/userInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        
        
        <el-col :span="12">
            <el-form-item label="工作状态" prop="workState"
                :rules="[
                 ]">
                <el-select v-model="inputForm.workState" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('work_state')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="招聘岗位分类" prop="jobClassification.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择招聘岗位分类"
            labelName = 'name'
            labelValue = 'id'
            :value = "inputForm.jobClassification.id"
            :limit="1"
            @getValue='(value) => {inputForm.jobClassification.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '名称'
            }
            ]"
            dataListUrl="/dlyrl/hr/jobclassification/jobClassification/list"
            entityBeanName="jobClassification"
            queryEntityUrl="/dlyrl/hr/jobclassification/jobClassification/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="手机号" prop="phone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.phone" placeholder="请填写手机号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="期望工作城市" prop="workingCity"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workingCity" placeholder="请填写期望工作城市"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工作经验年限" prop="workingYears"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workingYears" placeholder="请填写工作经验年限"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="邮箱" prop="email"
                :rules="[
                 ]">
              <el-input v-model="inputForm.email" placeholder="请填写邮箱"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="求职意向" prop="careerObjective"
                :rules="[
                 ]">
              <el-input v-model="inputForm.careerObjective" placeholder="请填写求职意向"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="薪资要求" prop="salaryRequirements"
                :rules="[
                 ]">
              <el-input v-model="inputForm.salaryRequirements" placeholder="请填写薪资要求"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工作性质" prop="natureOfWork"
                :rules="[
                 ]">
              <el-input v-model="inputForm.natureOfWork" placeholder="请填写工作性质"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="期望行业" prop="expectIndustry.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择期望行业"
            labelName = 'name'
            labelValue = 'id'
            :value = "inputForm.expectIndustry.id"
            :limit="1"
            @getValue='(value) => {inputForm.expectIndustry.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '名称'
            }
            ]"
            dataListUrl="/dlyrl/hr/jobclassification/jobClassification/list"
            entityBeanName="jobClassification"
            queryEntityUrl="/dlyrl/hr/jobclassification/jobClassification/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        
        <el-col :span="12">
            <el-form-item label="求职状态" prop="jobSearchingStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.jobSearchingStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('job_searching_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="期望岗位" prop="jobPosts"
                :rules="[
                 ]">
              <el-input v-model="inputForm.jobPosts" placeholder="请填写期望岗位"     ></el-input>
           </el-form-item>
        </el-col>
        
        <el-col :span="12">
            <el-form-item label="曾用名" prop="alternateName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.alternateName" placeholder="请填写曾用名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="民族" prop="natio"
                :rules="[
                 ]">
              <el-input v-model="inputForm.natio" placeholder="请填写民族"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="出生年月" prop="dateofbirth"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.dateofbirth"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="政治面貌" prop="politicsStatus"
                :rules="[
                 ]">
              <el-input v-model="inputForm.politicsStatus" placeholder="请填写政治面貌"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="婚否" prop="maritalStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.maritalStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="最高学历" prop="highestEducation"
                :rules="[
                 ]">
                <el-select v-model="inputForm.highestEducation" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('nature')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="学位" prop="degree"
                :rules="[
                 ]">
                <el-select v-model="inputForm.degree" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('nature')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="毕业时间" prop="graduationdate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.graduationdate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="专业" prop="specialty"
                :rules="[
                 ]">
              <el-input v-model="inputForm.specialty" placeholder="请填写专业"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="职称" prop="jobTitle"
                :rules="[
                 ]">
              <el-input v-model="inputForm.jobTitle" placeholder="请填写职称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="籍贯" prop="nativeplace"
                :rules="[
                 ]">
              <el-input v-model="inputForm.nativeplace" placeholder="请填写籍贯"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="有无处分记录" prop="ispunishment"
                :rules="[
                 ]">
                <el-select v-model="inputForm.ispunishment" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="户口所在地" prop="placeofdomicile"
                :rules="[
                 ]">
              <el-input v-model="inputForm.placeofdomicile" placeholder="请填写户口所在地"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="邮编" prop="zipCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.zipCode" placeholder="请填写邮编"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="健康状况" prop="healthCondition"
                :rules="[
                 ]">
                <el-select v-model="inputForm.healthCondition" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('healthcondition')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        
        <el-col :span="12">
            <el-form-item label="工作经历" prop="workExperience"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.workExperience" placeholder="请填写工作经历"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="教育经历" prop="educationExperience"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.educationExperience" placeholder="请填写教育经历"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="专业技能" prop="professionalSkill"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.professionalSkill" placeholder="请填写专业技能"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="语言能力" prop="languageSkills"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.languageSkills" placeholder="请填写语言能力"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="自我评价" prop="selfEvaluation"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.selfEvaluation" placeholder="请填写自我评价"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否有亲戚在本公司/职务" prop="iskithandkin"
                :rules="[
                 ]">
                <el-select v-model="inputForm.iskithandkin" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="简历头像" prop="resumeHead"
                :rules="[
                 ]">
              <el-upload ref="resumeHead"
                    v-if="visible"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/dlyrl/hr/resumeinformation/resumeInformation`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file) => {$window.open ((file.response && file.response.url) || file.url,'_blank') }"
                    :on-success="(response, file, fileList) => {
                       inputForm.resumeHead = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.resumeHead = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="5"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="resumeHeadArra">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">添加相关附件</div>
                  </el-upload>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="视频简历" prop="videoResume"
                :rules="[
                 ]">
              <el-upload ref="videoResume"
                    v-if="visible"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/dlyrl/hr/resumeinformation/resumeInformation`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file) => {$window.open ((file.response && file.response.url) || file.url,'_blank') }"
                    :on-success="(response, file, fileList) => {
                       inputForm.videoResume = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.videoResume = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="5"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="videoResumeArra">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">添加相关附件</div>
                  </el-upload>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="附件简历" prop="attachedResume"
                :rules="[
                 ]">
              <el-upload ref="attachedResume"
                    v-if="visible"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/dlyrl/hr/resumeinformation/resumeInformation`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file) => {$window.open ((file.response && file.response.url) || file.url,'_blank') }"
                    :on-success="(response, file, fileList) => {
                       inputForm.attachedResume = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.attachedResume = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="5"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="attachedResumeArra">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">添加相关附件</div>
                  </el-upload>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        resumeHeadArra: [],
        videoResumeArra: [],
        attachedResumeArra: [],
        inputForm: {
          id: '',
          userInformation: {
            id: ''
          },
          resumeHead: '',
          workExperience: '',
          educationExperience: '',
          remarks: '',
          workState: '',
          jobClassification: {
            id: ''
          },
          phone: '',
          workingCity: '',
          workingYears: '',
          email: '',
          careerObjective: '',
          salaryRequirements: '',
          natureOfWork: '',
          expectIndustry: {
            id: ''
          },
          professionalSkill: '',
          languageSkills: '',
          selfEvaluation: '',
          jobSearchingStatus: '',
          jobPosts: '',
          videoResume: '',
          attachedResume: '',
          alternateName: '',
          natio: '',
          dateofbirth: '',
          politicsStatus: '',
          maritalStatus: '',
          highestEducation: '',
          degree: '',
          graduationdate: '',
          specialty: '',
          jobTitle: '',
          nativeplace: '',
          ispunishment: '',
          placeofdomicile: '',
          zipCode: '',
          healthCondition: '',
          iskithandkin: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建个人简历信息`
        } else if (method === 'edit') {
          this.title = '修改个人简历信息'
        } else if (method === 'view') {
          this.title = '查看个人简历信息'
        }
        this.resumeHeadArra = []
        this.videoResumeArra = []
        this.attachedResumeArra = []
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/resumeinformation/resumeInformation/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.resumeInformation)
              this.inputForm.resumeHead.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.resumeHeadArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.inputForm.videoResume.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.videoResumeArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.inputForm.attachedResume.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.attachedResumeArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/resumeinformation/resumeInformation/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>